package com.lvs.zmwz.controller.app;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lvs.zmwz.auth.StpUserUtil;
import com.lvs.zmwz.comm.ResultEnum;
import com.lvs.zmwz.entity.SysManager;
import com.lvs.zmwz.entity.req.SysManagerReq;
import com.lvs.zmwz.entity.serach.SysManagerSearch;
import com.lvs.zmwz.exception.MyException;
import com.lvs.zmwz.service.ISysManagerService;
import com.lvs.zmwz.util.QPage;
import com.lvs.zmwz.util.ResultView;
import com.lvs.zmwz.util.RsaUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 后台账户表 前端控制器
 * </p>
 *
 * @author lbk
 * @since 2021-10-19
 */
@RestController
@RequestMapping("/api/front/manager")
public class AppSysManagerController {

    @Autowired
    private ISysManagerService iSysManagerService;

    /**
     * 修改用户
     * @param hjManager
     * @return
     */
    @PostMapping("/updateManager")
    public ResultView updateRole(SysManager hjManager) {
        String managerId= StpUserUtil.getLoginIdAsString();
        SysManager sysManager=this.iSysManagerService.getById(managerId);
        sysManager.setUtime(new Date());
        sysManager.setMPwd(RsaUtil.setRsaPwd(hjManager.getMPwd()));
        sysManager.setMName(hjManager.getMName());
        sysManager.setMPhone(hjManager.getMPhone());
        sysManager.setMEmail(hjManager.getMEmail());
        boolean count=this.iSysManagerService.updateById(sysManager);
        if(!count){
            throw new MyException(ResultEnum.CODE_2,"修改账户出现异常");
        }
        return ResultView.ok();
    }




}
